package com.example.dicos.controller;


import com.example.dicos.config.CommonResult;
import com.example.dicos.entity.dot.WxUserRoleRelationDto;
import com.example.dicos.service.WxRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

/**
 * <p>
 * 后台用户角色表 前端控制器
 * </p>
 *
 * @author 开发者
 * @since 2022-07-11
 */
@Api(tags = "角色模块")
@RestController
@RequestMapping("/wxRole")
public class WxRoleController extends BaseController{

    @Autowired
    private WxRoleService wxRoleService;

    /**
     * 查询角色列表
     *
     * @return
     */
    @ApiOperation("查询角色列表")
    @GetMapping("/queryWxRoleList")
    public CommonResult queryWxRoleList() {
        return CommonResult.success(wxRoleService.queryWxRoleList());
    }


    @ApiOperation("用户分配角色")
    @PostMapping("/addUserRole")
    public CommonResult addUserRole(@RequestBody WxUserRoleRelationDto wxUserRoleRelationDto) {
        try {
            return CommonResult.success(wxRoleService.addUserRole(wxUserRoleRelationDto));
        } catch (Exception e) {
            return CommonResult.failed(e.getMessage());
        }
    }



    @ApiOperation("根据用户id查询角色")
    @GetMapping("/queryWxRoleVoById")
    public CommonResult queryWxRoleVoById(@RequestParam("userId") Long userId){

        return CommonResult.success(wxRoleService.queryWxRoleVoList(userId));
    }



    @ApiOperation("当前用户的角色列表 <token获取id>")
    @GetMapping("/userRole/queryWxRoleVoList")
    public CommonResult queryWxRoleVoList(){

        return CommonResult.success(wxRoleService.queryWxRoleVoList(super.getUserById()));
    }

}

